﻿using Mapster;
using Service.Core.Repository;
using Service.Gateway.Domain.Db;
using Service.Gateway.Domain.Model;

namespace Service.Gateway.Application.Service;

public class GatewayServiceImpl(IRepository<ApiGatewayConfiguration> _repository) : IGatewayService
{
    public async Task<List<ApiGatewayDto>> QueryApiGatewayList()
    {
        var datas = await _repository.Db.Queryable<ApiGatewayConfiguration>()
               .Includes(s => s.ServiceRoutes).ToListAsync();
        return datas.Adapt<List<ApiGatewayDto>>();
    }

    public async Task<ApiGatewayDto> QueryApiGatewayById(long id)
    {
        var data = await _repository.Db.Queryable<ApiGatewayConfiguration>()
            .Where(s => s.Id == id)
            .Includes(s => s.ServiceRoutes)
            .FirstAsync();

        return data.Adapt<ApiGatewayDto>();
    }
}